package com.example.builderPattern;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 一餐
 * sun 2017-11-24.
 */
public class Meal {
    private List<Item> items = new ArrayList<>();

    //添加食物
    public List<Item> addItem(Item item) {
        if (Objects.isNull(items)) items = new ArrayList<>();
        items.add(item);
        return items;
    }

    // 获取餐费
    public float getCost() {
        float cost = 0.0f;
        if (Objects.nonNull(items) && !items.isEmpty())
            for (Item item : items) {
                cost += item.price();
            }
        return cost;
    }

    // 打印清单
    public void showItems(){
        if(Objects.isNull(items) || items.isEmpty())
            System.out.println("您还没有订餐！");
        for (Item item : items) {
            System.out.print("Item : " + item.name());
            System.out.print(",item.packing().pack() = " + item.packing().pack());
            System.out.println(",item.price() = " + item.price());
        }
    }
}
